package com.tj.jinzao.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.tj.jinzao.R;
import com.tj.jinzao.adapter.LabelListItemAdapter;
import com.tj.jinzao.base.BaseDataListFragment;
import com.tj.jinzao.base.IBaseView;
import com.tj.jinzao.model.Label;
import com.tj.jinzao.presenter.LabelPresenter;
import com.tj.jinzao.widgets.EmptyView;

import java.util.List;

/**
 * 标签列表
 * Created by wjy on 2019/1/1.
 */
public class LabelListFragment extends BaseDataListFragment<List<Label>, LabelPresenter, Label> implements IBaseView<List<Label>> {

    public static LabelListFragment newInstance() {
        LabelListFragment fragment = new LabelListFragment();
        if (fragment != null) {
            Bundle args = new Bundle(3);
            args.putString(ARG_TAG_ID, String.valueOf(1));
            args.putInt(ARG_LOAD_ID, 1);
            args.putInt(ARG_LAYOUT_RES_ID, R.layout.fragment_label_list);
            fragment.setArguments(args);
        }
        return fragment;
    }

    @Override
    public void onRequestNoData(String message) {
        setEmptyDataView();
    }

    @Override
    protected LabelPresenter createPresenter() {
        return new LabelPresenter(this);
    }

    @Override
    protected void createView(LayoutInflater inflater, View view) {
    }
    private LabelListItemAdapter labelListItemAdapter;

    @Override
    protected RecyclerView.Adapter createAdapter() {
        labelListItemAdapter=new LabelListItemAdapter(mContext, mData);
        return labelListItemAdapter;
    }

    @Override
    protected void requestData() {
        mPresenter.getLabelList();
    }

    @Override
    protected void setEmptyDataView() {
        mEmptyView.setVisibility(View.VISIBLE);
        mEmptyView.setState(EmptyView.State.NO_DATA, "没有内容哦");
    }

    @Override
    protected boolean resolveData(List<Label> labels) {
        return false;
    }

    @Override
    public void onRequestSuccess(List<Label> list) {
        super.onRequestSuccess(list);
        if (mPageNo <= 1) {
            mData.clear();
        }
        mData.addAll(list);
        showListView();

    }

    @Override
    protected void initData() {
        view.findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mContext.setResult(100, new Intent().putStringArrayListExtra("label", labelListItemAdapter.getListLable()));
                mContext.finish();
            }
        });
        view.findViewById(R.id.back_lay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getActivity().finish();
            }
        });
    }

    @Override
    protected void itemClicked(int position, Label data) {
    }
}
